#include <bits/stdc++.h>
#define rg register
#define pc putchar
#define gc getchar
#define pf printf
#define space pc(' ')
#define enter pc('\n')
#define me(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define FOR(i,k,t,p) for(rg int i(k) ; i <= t ; i += p)
#define ROF(i,k,t,p) for(rg int i(k) ; i >= t ; i -= p)
using namespace std ;
bool s_gnd ;
inline void read(){}
template<typename T,typename ...T_>
inline void read(T &x,T_&...p)
{
    x = 0 ;rg int f(0) ; rg char c(gc()) ;
    while(!isdigit(c)) f |= (c=='-'),c = gc() ;
    while(isdigit(c)) x = (x<<1)+(x<<3)+(c^48),c = gc() ;
    x = (f?-x:x) ;
    read(p...);
}
int stk[30],tp ;
inline void print(){}
template<typename T,typename ...T_>
inline void print(T x,T_...p)
{
    if(x < 0) pc('-'),x = -x ;
    do stk[++tp] = x%10,x /= 10 ; while(x) ;
    while(tp) pc(stk[tp--]^48) ; space ;
    print(p...) ;
}
bool S_GND ;
const int N = 1005 ;
const int INF = 1e9+7 ;
int n,q,ans,k ;
int a[N] ;
void Solve(int x)
{
    int le = x,ri = x,val = a[x] ;
    while(le != 1 || ri != n)
    {
        if(a[le-1] > val && a[ri+1] > val)
        {
            val = min(a[le-1],a[ri+1]),ans += k ; continue ;
        }
        if(a[le-1] <= val) --le,++ans ;
        if(a[ri+1] <= val) ++ri,++ans ;
    }
}
signed main()
{
//cerr<<(double)(&s_gnd-&S_GND)/1024.0/1024.0 ;
	freopen("summer.in","r",stdin) ;
	freopen("summer.out","w",stdout) ;
    read(n,k),a[0] = a[n+1] = INF ;
    FOR(i,1,n,1) read(a[i]) ; read(q) ;
    while(q--)
    {
        int x,l,r ; read(x,l,r),swap(a[x],a[x+1]) ;
        ans  = 0 ; FOR(i,l,r,1) Solve(i) ; print(ans),enter ;
    }
    return 0 ;
}